#include "stack.h"

#define NAMESIZE 32

//存储的用户数据类型
typedef struct
{
	int id;
	char name[NAMESIZE];
	int math;
	int chinese;
} score;

//由用户书写的回调函数
void print_s(void *record)
{
	score *st = record;
	printf("%d %s %d %d\n", st->id, st->name, st->math, st->chinese);
}

int main(void)
{
	STACK *st;
	st = stack_create(sizeof(score));
	if (st == NULL)
		exit(1);

	score tmp;

	for (int i = 0; i < 7; i++)
	{
		tmp.id = i;
		snprintf(tmp.name, NAMESIZE, "stu%d", i);
		tmp.math = rand() % 100;
		tmp.chinese = rand() % 100;
		if (stack_push(st, &tmp))
			exit(1);
	}

	while (1)
	{
		int ret = stack_pop(st, &tmp);
		if (ret == -1)
			break;
		print_s(&tmp);
	}

	stack_destory(&st);

	return 0;
}